//
//  ChatItemRoleView.swift
//  imprint
//
//  Created by 小柠檬🍋 on 2025/5/2.
//

import SwiftUI
import Kingfisher

struct ChatItemRoleView: View {
    @State var item: AiRoleBean
    
    var body: some View {
        HStack(alignment: .top){
            KFImage(URL(string: item.avatar.formatCdn()))
                .resizable()
                .placeholder{
                    Image(.appDefaultLogo)
                        .resizable()
                        .scaledToFill()
                        .padding(EdgeInsets(top: 10, leading: 10, bottom: 10, trailing: 10))
                        .frame(width: 40,height: 40)
                        .clipShape(Circle())
                }
                .background(Color.hex("515151").opacity(0.1))
                .scaledToFill()
                .frame(width: 40,height: 40)
                .clipShape(Circle())
            VStack(alignment: .leading) {
                Text(item.name ?? "")
                    .lineLimit(1)
                    .font(.system(size: 14))
                    .foregroundStyle(.bgNormalText2)
                Text(item.describe ?? "")
                    .lineLimit(2)
                    .font(.system(size: 14))
                    .foregroundStyle(.bgNormalText4)
            }
        }
        .frame(maxWidth: .infinity,alignment: .leading)
        .padding(.horizontal, 20)
        .padding(.vertical, 10)
        .background(themeManager.themeColor.opacity(item.select ? 0.1 : 0))
    }
    
}

#Preview {
    let role = AiRoleBean()
    role.name = "AI 助手"
    role.describe = "你好！有什么可以帮助你的？"
    
    return ChatItemRoleView(item: role).background(.bg)
}
